﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using IHISCETeim.Model;
using IHISCETeim.Library;
using IHISCETeim.BLL;
namespace IHISCETeim.Web.MachineSys.SysBasic
{
    public partial class OMenuAdd :PageBase
    {
        #region 
       
        protected override Permission[] PowerKey
        {
            get
            {
                return new Permission[] {  Permission.新增 };
            }
        }
        protected override string DWZRef
        {
            get
            {
                return "OMeunList";
            }
        }

        #endregion
        protected string GetPermission()
        {

            string perhtml = "";
            string peritemtemp = "<label><input type=\"checkbox\" name=\"PermissionTag\" value=\"{0}\" />{0}</label>";
            Array items;
            items = Enum.GetValues(typeof(Permission));
            // string item;
            foreach (Permission item in items)
            {
                perhtml = perhtml + string.Format(peritemtemp, item.ToString());
            }
            return perhtml;
        }

        protected string GetParMenuId()
        {
            string perhtml = "";

            string peritemtemp = "<option value=\"{0}\" style=\"font-weight:{3};\" >{2}{4}{1}</option>";
            List<OMenuInfo> alltop = OMenuController.GetAllParentMenu(0);
            // string item;
            perhtml = perhtml + "<option value='0' selected>顶级菜单...</option>";
            foreach (OMenuInfo item in alltop)
            {
                perhtml = perhtml + string.Format(peritemtemp, item.MenuId, item.MenuName,"","bold",item.DispayIndex);
                List<OMenuInfo> alltop2 = OMenuController.GetAllParentMenu(item.MenuId);
                foreach (OMenuInfo item2 in alltop2)
                {
                    perhtml = perhtml + string.Format(peritemtemp, item2.MenuId, item2.MenuName, "-->", "", item2.DispayIndex);
                }

            }
            return perhtml;
        }


        protected void Page_Load(object sender, EventArgs e)
        {
            if (GetRequestValue<string>("ajaxmethod", "") == "addmenu")
            {
                addmenu();
            }
        }

        protected void addmenu()
        {
            OMenuInfo obj = Request.SerializableObject<OMenuInfo>();
            string x = Request["PermissionTag"];
            //obj.IsAgent = false;
            //if (string.IsNullOrEmpty(x))
            //    AlertJson("请先选择页面功能权限.");
            if (OMenuController.AddOMenu(obj, x))
                SuccessJson("添加成功");
            else
                ErrorJson("添加失败");
        }

    }
}